package com.admin.action

import com.admin.service.ThemeClassService
import com.data.annotation.NoargAnnotation
import com.data.annotation.OpenAnnotation
import com.data.bean.ThemeClass
import com.data.util.JsonUtils
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Controller
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.ResponseBody
import javax.servlet.http.HttpServletRequest

/**
 * FileName: ThemeClassAction
 * Author:   HingLo
 * Date:     2017/11/6 11:02
 * Description: 主题案例分类
 */
@Controller
@OpenAnnotation
@NoargAnnotation
@RequestMapping("themeClass/admin/")
class ThemeClassAction {
    @Autowired
    private var themeClassService: ThemeClassService? = null

    /****
     *
     * 查看主题分类信息
     * @param request
     * @return
     */
    @RequestMapping("list")
    fun listThemeClassAction(request: HttpServletRequest): String {
        val list = this.themeClassService!!.listThemeClassService()
        request.setAttribute("dataMap", list)
        return "WEB-INF/admin/case/listCase"
    }

    /****
     *
     * 查看主题分类信息
     * @param request
     * @return
     */
    @RequestMapping("listClass")
    @ResponseBody
    fun listClassAction(request: HttpServletRequest): List<ThemeClass> {
        val list = themeClassService!!.listThemeClassService()
        print(list)
        return list
    }

    /**
     * 修改分类信息
     *
     * @param id
     * @param name
     * @param request
     * @return
     */
    @PostMapping("changeThemeClass")
    @ResponseBody
    fun changeThemeClassAction(id: String, name: String, request: HttpServletRequest): Map<String, Any> {
        val bool = this.themeClassService!!.changeThemeClassService(id, name)
        return JsonUtils.returnMassageUtils(bool, if (bool) "修改成功" else "修改失败")
    }

    /**
     * 进入到添加主题界面
     *
     * @param request
     * @return
     */
    @RequestMapping("addThemeClass")
    fun addThemeClassAction(request: HttpServletRequest): String {
        return "WEB-INF/admin/case/addCase"
    }

    /**
     * 提交添加主题分类
     *
     * @param name
     * @param request
     * @return
     */
    @PostMapping("submitThemeClass")
    @ResponseBody
    fun submitThemeClassAction(themeClass: ThemeClass, request: HttpServletRequest): Map<String, Any> {
        val bool = this.themeClassService!!.submitThemeClassService(themeClass)
        return JsonUtils.returnMassageUtils(bool, if (bool) "添加成功" else "添加失败")
    }

    /**
     * 删除主题分类
     *
     * @param id
     * @param request
     * @return
     */
    @PostMapping("delete")
    @ResponseBody
    fun deleteThemeClassAction(id: String, request: HttpServletRequest): Map<String, Any> {
        val bool = this.themeClassService!!.deleteThemeClassService(id)
        return JsonUtils.returnMassageUtils(bool, if (bool) "删除成功" else "删除失败")
    }
}
